
import axios from "axios";
import { defineStore } from "pinia";
import router from "@/router";
const Store = defineStore("Store", {
  state() {
    return {
      contentid: 0,
      token: 0,
      userInfo: [] /* 用户信息 */,
      cartNumber: 0, /* 购物车数量 */
      newProduction: [],/* 新品上线 */
      yourLikes: [],/* 为你推荐 */
      goodsDetail: [], /* 商品详情 */
      cartInfo: [], /* 购物车信息 */
      searchGoodsInfo: [],/* 搜索信息 */
      searchKey: '', /* 是搜索关键字 */
      category: [],/* 类别 */
      orderItem: [],/* 订单商品 */
      orderDetail: [],/* 订单详情 */
      from: '',/* 判断从哪来  0代表搜索 1代表类别导航*/
      categoryId: 0, /* 类别id */
    };
  },
  actions: {
    getAll() {
      axios
        .post(`http://localhost:8080/content/todo/${this.userid}`)
        .then((res) => {
          console.log(res.data);
          this.todolist = res.data;
          console.log(this.todolist);
          // router.push('/add')
        });
    },

    getCount() {
      axios
        .post(`http://localhost:8080/content/donePercent/${this.userid}`)
        .then((res) => {
          /* console.log(res.data) */
          this.dataInfo = res.data;
          console.log(this.dataInfo);
          router.push("/add");
        });
    },
  },
  persist: {
    enabled: true, // 这个配置代表存储生效，而且是整个store都存储
  },
});
export default Store;
